﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FoodManager
{
    public partial class frQuanLyNguoiDung : Form
    {
        public frQuanLyNguoiDung()
        {
            InitializeComponent();
        }

        private void frQuanLyNguoiDung_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'db.tblusers' table. You can move, or remove it, as needed.
            this.tblusersTableAdapter.Fill(this.db.tblusers);
            // TODO: This line of code loads data into the 'db.tblusers' table. You can move, or remove it, as needed.
            this.tblusersTableAdapter.Fill(this.db.tblusers);

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataTable data=tblusersTableAdapter.GetDataById(Convert.ToInt32(listBox1.SelectedValue));
            if(data.Rows.Count>0){
                cbTrangThai.Text = Functions.GetStringTrangThai(Convert.ToInt32(data.Rows[0]["trangthai"]));
            }
        }

        private void btnInsert_Click(object sender, EventArgs e)
        {
            if (txtPassword.Text == txtDiachi.Text)
            {
                tblusersTableAdapter.Insert(txtUsername.Text, txtPassword.Text, Convert.ToByte(Functions.GetIntTrangThai(cbTrangThai.Text)));
                db.tblusers.Rows.Clear();
                tblusersTableAdapter.Fill(db.tblusers);
            }
            else { MessageBox.Show("Password nhập chưa đúng."); }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            tblusersTableAdapter.DeleteQuery(Convert.ToInt32(listBox1.SelectedValue));
            db.tblusers.Rows.Clear();
            tblusersTableAdapter.Fill(db.tblusers);
        }
    }
}
